package org.vectrics.recruiter.struts;

import org.apache.log4j.*;
import javax.servlet.http.HttpServletRequest;
import org.vectrics.recruiter.user.*;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;

public class SaveUserEmploymentAction extends Action {
    private static Category log = Category.getInstance(SaveUserEmploymentAction.class);
    public static String ACTION_NAME = "save_user_emp";
    public static String USER_PARAM = "user";
    public static String EMP_ID_PARAM = "emp_id";
    public static String DESCRIPTION_PARAM = "desc";
    public static String TITLE_PARAM = "title";
    public static String START_DATE_PARAM = "start";
    public static String END_DATE_PARAM = "end";
    public static String COMPANY_PARAM = "comp";

    private boolean newUser = false;
    private RecruitUserProfile userProfile = null;
    

    public SaveUserEmploymentAction() {
    	log.debug("SaveUserEmploymentAction - constructor");
    }

	public ActionForward execute(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)	throws JspException {
    	/*
        log.debug("doPerform() called");
        String user = request.getParameter(USER_PARAM);
        String empId = request.getParameter(EMP_ID_PARAM);
        String cancel = request.getHttpRequest().getParameter("cancel");
        String description = request.getParameter(DESCRIPTION_PARAM);
        String title = request.getParameter(TITLE_PARAM);
        String companyName = request.getParameter(COMPANY_PARAM);
        String startDateStr = request.getParameter(START_DATE_PARAM);
        String endDateStr = request.getParameter(END_DATE_PARAM);
        

        if (cancel == null) {
            log.debug("doPerform() submit button pressed - saving user..");
            if (user.equals("")) {
                log.error("doPerform() - user not specified in params.");
                request.addInvalidParam("user", "User not specified");
            }
            else {
                log.debug("doPerform() - attempting to find user.");
                
                userProfile = RecruitManager.getInstance().getUserProfile(request);
                
                User appUser = null;
                if (userProfile != null) {
                    appUser = userProfile.getUser();
                }

                if (appUser == null) {
                    log.warn("doPerform() - could not find user - might not be logged in.");
                }
                else {
                    log.info("doPerform() - found user");
                }
            
            UserEmployment emp = null;
            if (empId == null) {
                emp = userProfile.createEmployment();
            }                   
            else {
                emp = userProfile.findEmployment(empId);
            }
            
    
                
                
            if (request.hasInvalidParams() == false) {
            
                //Read params into appUser object
                emp.setTitle(title);
                emp.setDescription(description);
                emp.setCompanyName(companyName);
                
            }
            else {
                log.debug("doRender() - invalid params - not saving employment.");
            }
            }
        }
        else {
            log.debug("cancel pressed, no action.");
        }
       
        */
		return (mapping.findForward("success"));
    }
    
}
